import { Component, ElementRef, inject, input, OnInit, viewChild } from '@angular/core';
import { startApp } from 'wujie';
import { WuJieService } from './wujie.service';

@Component({
  selector: 'NgWuJie',
  imports: [],
  template: `
    <div #subRef></div>`,
  styles: ``,
})
export class WuJieComponent implements OnInit {
  name = input.required<string>();
  ref = viewChild<ElementRef<HTMLElement>>('subRef');

  wuJie = inject(WuJieService);


  ngOnInit() {
    let option = this.wuJie.options.find(s => s.name === this.name());
    if (!option) {
      throw Error(`没有找到对应的子应用，name:${this.name()}`);
    }
    option.el = this.ref()?.nativeElement || this.name();
    startApp(option).then();
  }
}
